SSRS Viewer for WinRT
Step 2 of 3: Adding Code

In the last step you added a C1SsrsViewer control to your application. In this step, you'll add code to the application to allow user authentication, printing, and customized page settings.

Complete the following steps:

  1. Switch to Code view and import the following namespace:
C#
Copy Code
using C1.Xaml.Document;
  1.  Specify the user credentials by adding the following code below the InitializeComponent() method:
C#
Copy Code
 ssrsViewer.Credential = new System.Net.NetworkCredential("user_name", "user_password");
  1.  Next, subscribe to the PrintManager's PrintTaskRequested event. This will allow users to print their reports. Your code should resemble the following:
C#
Copy Code
 public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
 
            ssrsViewer.Credential = new System.Net.NetworkCredential("administrator", "Support@focus1");
            PrintManager.GetForCurrentView().PrintTaskRequested += MainPage_PrintTaskRequested;
        }
 
        async void MainPage_PrintTaskRequested(PrintManager sender, PrintTaskRequestedEventArgs args)
        {
            await ssrsViewer.CreatePrintTaskAsync(args);
        }
To process this event, call the C1SsrsViewer's CreatePrintTaskAsync() method.
  1. Then, add the code for the Settings Charm. This will allow users to specify custom page settings. Add the following code to the page constructor:
C#
Copy Code
SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested;

And then add the following code as the event handler:

C#
Copy Code
void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
        {
            var pageSettingsCommand = new SettingsCommand(Guid.Empty, "Page Settings",
                (command) =>
                {
                    ssrsViewer.PageSettingsFlyout.Show();
                });
            args.Request.ApplicationCommands.Add(pageSettingsCommand);
        }
  1. Finally, add the code to unsubscribe from both the events when the page is unloaded. If you don't clean up, you won't be able to open the same report again. Add the following code to the page constructor:
C#
Copy Code
this.Unloaded += (sender, e) =>
        {
            SettingsPane.GetForCurrentView().CommandsRequested -= MainPage_CommandsRequested;
            PrintManager.GetForCurrentView().PrintTaskRequested -= MainPage_PrintTaskRequested;
        };

 In this step you added code to your application to load and print a report. You also added code that will allow users to specify page settings using the Settings Charm. In the next step you'll run your application.

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback